'use strict';
/**
 * Created by FreezeSoul on 2015/9/25.
 */
define([
        'angular',
        'app/modules/editor/define',
        'app/modules/editor/services/sidebar'
    ],
    function(angular) {
        angular.module('ad.editor')
            .directive('adEditorSidebarDirective',['$rootScope','$state','adEditorSidebarService',function($rootScope,$state,service) {
                var sv = service;
                return {
                    templateUrl:'app/modules/editor/views/sidebar.tpl.html',
                    restrict: 'E',
                    replace: true,
                    link:function($scope, $element, $attrs){
                        $scope.menus = sv.menus;
                        $scope.menuclick = function(menu){
                            if(menu.type == 'toggle'){
                                menu.isOpen = !menu.isOpen;
                            }else{
                                $state.go(menu.state);
                            }
                            return false;
                        };
                        $scope.pageclick = function(page){
                            $rootScope.$broadcast('ad.message.pathinfo', page.name);
                            $state.go(page.state);
                            return false;
                        }
                    }
                }
            }]);

    });
